package cn.yunhe.service.impl;

import cn.yunhe.dao.CaseDao;
import cn.yunhe.entity.Case;
import cn.yunhe.service.CaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("caseService")
public class CaseServiceImpl implements CaseService {

    @Resource
    private CaseDao caseDao;

    public CaseDao getCaseDao() {
        return caseDao;
    }

    public void setCaseDao(CaseDao caseDao) {
        this.caseDao = caseDao;
    }

    @Override
    public Page getLikeCaseListByPage(Map<String,Object> cond) {
         Page page=new Page();
         int pageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));
         int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));
         int totalNums=caseDao.getLikeCaseCount(cond);
         page.setTotal(totalNums);
         page=PageHelper.startPage(pageNum,pageSize);
         List<Case> caseList=caseDao.getLikeCaseList(cond);
         return page;
    }

    @Override
    public boolean addCase(Case cases) {
          return caseDao.addCase(cases);
    }

    @Override
    public boolean updateCase(Case cases) {
        System.out.println("执行了修改方法");
        return caseDao.updateCase(cases);
    }

    @Override
    public boolean delCase(Case cases) {
        return  caseDao.delCase(cases);
    }

   /* @Override
    public boolean delCases(List<Case> caseList) {
        return  caseDao.delCases(caseList);
    }*/
    @Override
    public int getLikeCaseCount(Map<String,Object> cond) {
         return caseDao.getLikeCaseCount(cond);
    }

    @Override
    public Page getPageCaseListByCaseState(Map<String, Object> cond) {
         Page page=new Page();
         int pageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));

         int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));
        System.out.println(pageNum+","+pageSize);
        System.out.println(cond.get("caseState"));
         page.setTotal(caseDao.getCaseCountByCaseState(cond));
         page=PageHelper.startPage(pageNum,pageSize);
         List<Case> caseList=caseDao.getCaseListByCaseState(cond);
        System.out.println(caseList.size());
         return page;
    }

    @Override
    public Case getCaseInfoByCaseUuid(String caseUuid) {
        return caseDao.getCaseInfoByCaseUuid(caseUuid);
    }

    @Override
    public boolean updateCaseStateTo0(String caseUuid) {
        return caseDao.updateCaseStateTo0(caseUuid);
    }


}
